package bill.java.lab.client.bitManipulations;

public class NumOfOnesInAnInteger {
	public static void main(String [] args){
	
		for(int i = -8; i <= 8; i++){
			numOfOnes2(i);
			numOfOnes(i);
			System.out.println("+++++++++++++++++++++++++++");
		}
	}
	
	static void numOfOnes2(int number){
		int counter = 0;
	
		for(int i = 0; i < 32 ; i ++){
			int power = 1<<i;
			if((power & number) == power ){
				counter ++;
			}
		}
		System.out.println("Method numOfOnes2 :the number of 1's in " + number + " is " + counter);
	}
	
	static void numOfOnes(int n){
		int mm = n;
		int counter = 0;
		while(n > 0){
			if((1 & n )== 1){
				counter ++;
			}
			 n = n >> 1;
		}
		System.out.println("Method numOfOnes: the number of 1's in " + mm + " is " + counter);
	}
}
